<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Solution_control extends CI_Controller {
	
	function __construct()
	{
		parent::__construct();
		$this->load->helper(array('form', 'url'));
		$this->load->model('upload_model');
		$this->load->model('projekt_model');
		$this->load->library(array('session', 'form_validation'));
		$this->form_validation->set_rules('solution', 'Popis', 'required');
	}

	function index($mid)
	{	
		if ( !$this->session->userdata('logged_in') ) {
		
			redirect('projekt/logged');
		
		}

		$sid = $this->upload_model->get_sid($mid);

		$content = $this->projekt_model->GetOneSolution($sid);

		if ($this->form_validation->run() == FALSE)
		{	
			if(isset($content[0])){
				$vstup = $content[0];
			} else {
				$vstup = FALSE;
			}
			$data = array('mid' => $mid, 'content' => $vstup);
			$this->load->view('solution', $data);
		}
		else
		{	
			$this->session->set_flashdata('mid', $mid);
			$popis = $this->input->post('solution');
			$this->upload_model->upload_text($popis, $mid);
			$sid = $this->upload_model->get_sid($mid);
			redirect('attachment_control/index/'.$sid);
		}
	}
}
?>
